var async = require('async');
/**
 * sync:同步调用
 */
function Person() {
  this.name = 'andy';
  this.answer = function(callback) {
    console.log('I\'am ' + this.name);
    callback();
  };
  this.think = function(callback) {
    console.log('I\'am thinking!');
    callback();
  };
}

var person = new Person();
// 1.嵌套

// 2.递归调用
function executeFunc(funcs, count, sum) {
  if (count == sum) {
    return;
  } else {
    funcs[count](function() {
      count++;
      executeFunc(funcs, count, sum);
    });
  }
}
var funcs = [person.think,person.answer];
var len = funcs.length;
executeFunc(funcs,0,len);
// 3.调用类库
async.series(
  [
    person.think,
    person.answer
  ]
);

/**
 * 回调
 */
function haveBreakfast(food, drink, callback) {
  console.log('早餐' + food + ', ' + drink);
  if (callback && typeof(callback) === "function") {
    callback();
  }
}

haveBreakfast('toast', 'coffee', function() {
  console.log('早餐吃完了，工作了啦!');
});


